package org.example.request;
import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.servlet.http.HttpServletRequest;

@RestController
public class TestJsonController {

	private List<BookList> pList = null;

	public TestJsonController() {
		pList = new ArrayList<BookList>();
		BookList p1 = new BookList();
		p1.setAuthor("罗贯中");
		p1.setPrice("22");
		p1.setBookName("西游记");
		p1.setIsbn("1");
		pList.add(p1);

	}

	@GetMapping("/all")
	public List<BookList> getAll() {
		return pList;
	}

	@PutMapping("/add")
	public List<BookList> addPerson( BookList user) {
		pList.add(user);
		return pList;
	}

	@GetMapping("/find")
	public BookList findPerson(HttpServletRequest request) {
		BookList result = new BookList();
		String name = request.getParameter("name");
		for (int i = 0; i < pList.size(); ++i) {
			if (name.equals(pList.get(i).getIsbn())) {
				result = pList.get(i);
				break;
			}
		}
		return result;
	}

	@DeleteMapping("/del")
	public List<BookList> delPerson(HttpServletRequest request) {
		String name = request.getParameter("name");
		for (int i = 0; i < pList.size(); ++i) {
			if (name.equals(pList.get(i).getIsbn())) {
				pList.remove(i);
				break;
			}
		}
		return pList;
	}
	@PostMapping("/update")
	public List<BookList> update(BookList user, HttpServletRequest request) {
		String name=request.getParameter("bookName");
		for(int i=0; i<pList.size(); ++i) {
			if(name.equals(pList.get(i).getBookName())) {
				pList.set(i, user);
				break;
			}
		}

		return pList;

	}
}
package com.example.demo.service;

import org.springframework.stereotype.Service;
import com.example.demo.model.SensorData;

@Service
public class SensorDataService {

	public <SensorData> SensorData processData(SensorData data) {
		// 这里是处理逻辑的示例
		double adjustedTemperature = adjustTemperature(data.getTemperature());
		double adjustedHumidity = adjustHumidity(data.getHumidity());
		double adjustedSoilMoisture = adjustSoilMoisture(data.getSoilMoisture());
		double adjustedLightIntensity = adjustLightIntensity(data.getLightIntensity());

		data.setTemperature(adjustedTemperature);
		data.setHumidity(adjustedHumidity);
		data.setSoilMoisture(adjustedSoilMoisture);
		data.setLightIntensity(adjustedLightIntensity);

		return data;
	}

	private double adjustTemperature(double temperature) {
		// 示例：将摄氏温度转换为华氏温度
		return temperature * 9/5 + 32;
	}

	private double adjustHumidity(double humidity) {
		// 示例：简单地确保湿度百分比在合理范围内
		return Math.min(Math.max(humidity, 0), 100);
	}

	private double adjustSoilMoisture(double soilMoisture) {
		// 示例：转换土壤湿度为适合显示的格式
		return soilMoisture * 100;  // 假设需要百分比格式
	}

	private double adjustLightIntensity(double lightIntensity) {
		// 示例：处理光照强度数据
		return lightIntensity / 1000;  // 假设需要以千勒克斯为单位显示
	}
}
